package top.guoyang.springboot3.service.api.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import top.guoyang.springboot3.entity.api.HistoryResult;
import top.guoyang.springboot3.service.api.HistoryService;
import top.guoyang.springboot3.service.message.BaseApiService;
import top.guoyang.springboot3.util.JsonUtils;

@Service
@RequiredArgsConstructor
@Slf4j
public class HistoryServiceImpl extends BaseApiService implements HistoryService {
    private final RestTemplate restTemplate;


    @Override
    public HistoryResult getHistory() {
       String url=String.format(HISTORY_URL,"1");
       String result=restTemplate.exchange(url, HttpMethod.GET, buildHttpEntity(), String.class).getBody();
      if (StringUtils.hasText( result)){
          return JsonUtils.parse(result, HistoryResult.class);
      }
      return null;
    }
}
